<template>
  <div>
    <video ref="videoPlayer" class="video-js vjs-default-skin vjs-big-play-centered"></video>
  </div>
</template>

<script>
import videojs from 'video.js';
import 'video.js/dist/video-js.css';

export default {
  name: "LivePlayer",
  props: {
    src: String,
  },
  watch: {
    src: {
      handler(val) {
        const options = {
          sources: [{
            // src: 'https://live.cgtn.com/1000/prog_index.m3u8',
            src: val,
            type: 'application/x-mpegURL'
          }],
          autoplay: true,
          // 隐藏控制栏
          controls: true,
          fluid: true,
          playsinline: true,
          muted: true,
        };
        console.log(this.src, "直播地址")
        if (this.player) {
          this.player.dispose();
          this.player = null;
        }
        this.player = videojs(this.$refs.videoPlayer, options);
      }
    }
  },
  mounted() {

  },
  beforeDestroy() {
    if (this.player) {
      this.player.dispose();
    }
  }
};
</script>
